﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using APC.Common;

namespace APC
{
    class MenuObject
    {

        #region enum

        public enum eMenuType { TypeMenu, TypeLocation, TypeRawMaterial, TypeIngredient, TypeRecipe, TypeOrder, TypeReport, TypeLocationFolder}
        public enum MainMenu { MenuNonSpecific, MenuRawMaterial, MenuRecipe, MenuLocation } //The main menu context

        #endregion

        #region Declarations

        private DataSystemDataContext ctxSystem;
        

        #endregion

        #region Properties

        public object Tag
        {
            set { _Tag = value; }
            get { return _Tag; }
        }
        private object _Tag = null;

        public int Id
        {
            set { _Id = value; }
            get { return _Id; }
        }
        private int _Id = 0;

        public bool Expand
        {
            set { _Expand = value; }
            get { return _Expand; }
        }
        private bool _Expand;

        public eMenuType MenuType
        {
            set { _MenuType = value; }
            get { return _MenuType; }
        }
        private eMenuType _MenuType;

        /// <summary>
        /// A submenu can appear i more than one mainmenu. Therefore flag the menu context to determine action on treenode clik
        /// </summary>
        public MainMenu MenuContext
        {
            set { _MenuContext = value; }
            get { return _MenuContext; }
        }
        private MainMenu _MenuContext = MainMenu.MenuNonSpecific;

        /// <summary>
        /// Holds a object like RawMaterial, Recipe, Order, etc
        /// </summary>
        public object ItemObject
        {
            set { _ItemObject = value; }
            get { return _ItemObject; }
        }
        private object _ItemObject = null;

        #endregion

        #region Constructors

        public MenuObject()
        {
            ctxSystem = new DataSystemDataContext(new Data().ConnectionString);
        }

        #endregion

        #region Methods

        /// <summary>
        /// Returns full menu structure
        /// </summary>
        /// <returns></returns>
        public List<APC.Common.MenuSystem> MenuStructure()
        {
          List<APC.Common.MenuSystem> lstMenuSystem = new List<APC.Common.MenuSystem>();

          lstMenuSystem = ctxSystem.MenuSystems.OrderBy(x => x.Sort).ToList(); //.Where(mnu => mnu.Parent_ID == -1).ToList();

          return lstMenuSystem;
        }

        /// <summary>
        /// Translate a menu text to active language
        /// </summary>
        /// <returns></returns>
        public string TranslateString(int? LanguageId, string UILang)
        {
            string s = "";

                UILanguage ui = (from ul in ctxSystem.UILanguages
                                 where ul.ID == LanguageId
                                 select ul).FirstOrDefault();

                if (ui != null)
                {
                    switch (UILang)
                    {
                        case "en_US":
                            s = ui.en_US;
                            break;

                        case "dk_DK":
                            s = ui.dk_DK;
                            break;

                        case "ko_KR":
                            s = ui.ko_KR;
                            break;

                        default:
                            s = ui.en_US;
                            break;
                    }
                }
 
               return s;  
        }


        #endregion
    }
}
